package com.mmall.common;

import com.mmall.dao.SysAclModuleMapper;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获取spring上下文
 * Created by megan on 2018/1/21.
 */
@Component("applicationContextHelper")
public class ApplicationContextHelper implements ApplicationContextAware{

    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }

    public static <T> T  popBean(String name ,Class<T> clazz){
        if(applicationContext == null){
            return null;
        }
        return  applicationContext.getBean(name,clazz);
    }

    public static <T> T popBean(Class<T> clazz) {
        if (applicationContext == null) {
            return null;
        }
        return applicationContext.getBean(clazz);
    }

}
